<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">

<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="layer/JQuery/jquery-3.1.1.min.js"></script>
    <script src="layer/layer/layer.js"></script>
    <link rel="stylesheet" href="layui/css/layui.css"/>
    <script src="layui/layui.js"></script>

    <style>
        .layui-input-block {
            margin-right: 600px;
        }
    </style>
</head>

<body>
<form class="layui-form" th:action="@{/user}" method="post">
    <div class="layui-form-item" style="margin-top: 10px">
        <label class="layui-form-label">工号</label>
        <div class="layui-input-block">
            <input type="text" id="uid" name="uid" lay-verify="required" placeholder="请输入工号(8位)（必填）" autocomplete="off"
                   class="layui-input" minlength="8" maxlength="8">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-block">
            <input type="text" id="upwd" name="upwd" lay-verify="required" placeholder="请输入密码（必填）" autocomplete="off"
                   class="layui-input" maxlength="64">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">科室</label>
        <div class="layui-input-block">
            <input type="text" id="udept" name="udept" lay-verify="required" placeholder="请输入科室名称（必填）" autocomplete="off"
                   class="layui-input" maxlength="50">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">用户类别</label>
        <div class="layui-input-block">
            <input type="text" id="utype" name="utype" lay-verify="required" placeholder="请输入用户类别（必填）" autocomplete="off"
                   class="layui-input" maxlength="20">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">联系方式</label>
        <div class="layui-input-block">
            <input type="text" id="uphone" name="uphone" placeholder="请输入联系方式" autocomplete="off"
                   class="layui-input" maxlength="20">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
            <input type="text" id="umemo" name="umemo" placeholder="请输入备注信息" autocomplete="off"
                   class="layui-input" maxlength="20">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" id="addbutton" lay-submit="" lay-filter="demo">提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            <a th:href="@{/users}">
                <input type="button" class="layui-btn layui-btn-primary" value="返回" style="margin-left: 9px;"></input>
            </a>
        </div>
    </div>

</form>

<script>
    layui.use('form', function () {
        var form = layui.form;
        //监听提交
        form.on('submit(formDemo)', function (data) {
            layer.msg(JSON.stringify(data.field));
            return false;
        });
    });

    function judgeEmpty(str) {
        var temp = $(str).val();
        if(temp.replace(/[ ]/g, '')==''){
            $(str).val("")
        }
    }

    $("#uid").blur(function () {
        judgeEmpty("#uid")
    });

    $("#uid").blur(function () {
        judgeEmpty("#upwd")
    });

    $("#uid").blur(function () {
        judgeEmpty("#udept")
    });

    $("#uid").blur(function () {
        judgeEmpty("#utype")
    });

    $("#uid").blur(function () {
        judgeEmpty("#uphone")
    });

    $("#uid").blur(function () {
        judgeEmpty("#umemo")
    });

</script>
</body>

</html>